package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.model.pjos.Evection;
import cn.gson.springboot.model.pjos.EvectionRecord;
import cn.gson.springboot.model.service.afterservice.EvectionService;
import cn.gson.springboot.model.vo.aftervo.EvectionVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/eve")
public class EvectionController {

    @Autowired
    EvectionService sc;

    @RequestMapping("/evet-page")
    @ResponseBody
    public Map<String,Object> evetPage(Integer employeesId, Integer fatherDeptId, String data, String date, String sites, Integer currPage, Integer pageSize){
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<Evection> evet = sc.selectEvetPage(employeesId, fatherDeptId, data,date,sites);

        Map<String,Object> map = new HashMap<>();
        map.put("rows",obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total",obj.getTotal());        //总条数
        return map;
    }

    @RequestMapping("/delete-evet")
    @ResponseBody
    public void deleteEvet(Integer apprId,Integer evetId){
        sc.deleteByEvetId(apprId,evetId);
    }

    @RequestMapping("/save-evet")
    @ResponseBody
    public void saveEvet(@RequestBody EvectionVo evet){
        sc.addEvet(evet);
    }

    @RequestMapping("/check-evet")
    @ResponseBody
    public Evection checkEvet(Integer evetIds){
        return sc.selectEvet(evetIds);
    }

    @RequestMapping("/save-cord")
    @ResponseBody
    public void saveCord(String substance, Integer employeesId, Integer evetId){
        sc.addRecord(substance ,employeesId, evetId);
    }

    @RequestMapping("/cord-evetid")
    @ResponseBody
    public List<EvectionRecord> CordEvetId(Integer evetId){
        return sc.selectCordEvetId(evetId);
    }

    @RequestMapping("/complete-evet")
    @ResponseBody
    public void completeEvet(Integer evetId){
        sc.complete(evetId);
    }
 }
